package Test;

import java.io.File;
import java.util.Vector;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import View.Client;
import View.ClientManager;

public class ClientTest {
	ClientManager manager = new ClientManager();
	String file = "ClientListTest.xml";
	
	@Before
	public void testCreateXMLFile() {
		boolean actual = manager.createXMLFile("ClientListTest");
		boolean expected = true;
		Assert.assertEquals(expected, actual);
	}

	@Test
	public void testIsFileExists() {
		boolean actual = manager.isFileExists("ClientListTest");
		boolean expected = true;
		Assert.assertEquals(expected, actual);
	}
	
	@Test
	public void testIsFileExists2() {
		boolean actual = manager.isFileExists("ClientTemp");
		boolean expected = false;
		Assert.assertEquals(expected, actual);
	}
	
	@Test
	public void testNumberOfClients() {
		
		int actual = manager.numberOfClients(file);
		Vector clients = manager.ViewClientList(file);
		int expected = clients.size();
		Assert.assertEquals(expected, actual);
	}

	@Test
	public void testViewClientList() {
		Vector<Client> actual = manager.ViewClientList(file);
		Vector<Client> expected = new Vector<Client>();
		expected.addElement(new Client("abc", "123456"));
		expected.addElement(new Client("efg", "123456"));
		
		int n = expected.size();
		int d = 0;
		if(n == actual.size()){
			for(int i = 0; i < actual.size(); i++){
				if(actual.get(i).getUser().equals(expected.get(i).getUser())
						&& actual.get(i).getPassword().equals(expected.get(i).getPassword()))
					d++;
			}
		}
		Assert.assertEquals(n, d);
	}

	@Test
	public void testAddClient() {
		Client client = new Client("panda", "123456");
		boolean actual = manager.AddClient(file, client);
		boolean expected = true;
		Assert.assertEquals(expected, actual);
	}

	@Test
	public void testTestInformation() {
		int actual = manager.testInformation(file, "efg", "123456");
		int expected = 1;
		Assert.assertEquals(expected, actual);
	}

	@Test
	public void testUpdateClientInformation() {
		boolean actual = manager.UpdateClientInformation(file, "panda", null, "1234");
		boolean expected = true;
		Assert.assertEquals(expected, actual);
	}
	
	@Test
	public void testUpdateClientInformation1() {
		boolean actual = manager.UpdateClientInformation(file, "panda", "pandaCopy", null);
		boolean expected = true;
		Assert.assertEquals(expected, actual);
	}
	
	@Test
	public void testUpdateClientInformation2() {
		boolean actual = manager.UpdateClientInformation(file, "pandaCopy", "panda", "123456");
		boolean expected = true;
		Assert.assertEquals(expected, actual);
	}
	
	@Test
	public void testDeleteClient() {
		boolean actual = manager.DeleteClient(file, "panda");
		boolean expected = true;
		Assert.assertEquals(expected, actual);
	}
	
	@After
	public void clean()
	{
		File file = new File(this.file);
		if(file.exists())
			file.delete();
	}
}
